home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / C / Applications / Moscow ML 1.42 / e_mac / rename_patch.c < prev    next >
Encoding:
Text File  |  1997-05-15  |  1.1 KB  |  46 lines  |  [TEXT/CWIE]

  1. // rename_patch.c
  2. // 15May1997 e
  3.  
  4. // MSL 2.1.1 doesn't rename directories; here's a fix...
  5.  
  6. #include <stdio.h>
  7. #include <file_io.h>
  8. #include "os_mac_str.h" // c_to_p()
  9.  
  10. static OSErr e_path2fss( const char *filename, FSSpec *fss )
  11. {
  12.   Str255 buf;
  13.   long cur_dir;
  14.   short cur_vol;
  15.  
  16.   c_to_p( (char *)filename, buf );
  17.   HGetVol( NULL, &cur_vol, &cur_dir );
  18.   return FSMakeFSSpec( cur_vol, cur_dir, buf, fss );
  19. }
  20.  
  21. #define io_result(ioResult) ((ioResult == noErr) ? (int) __no_io_error : (int) __io_error)
  22.  
  23. int __rename_file(const char * old_name, const char * new_name)
  24. {
  25.     FSSpec                    old_spec, new_spec;
  26.     OSErr                        ioResult;
  27.     HParamBlockRec    pb;
  28.     
  29.     if ((ioResult = e_path2fss(old_name, &old_spec)) != 0 )
  30.         return(__io_error);
  31.     
  32.     if ((ioResult = e_path2fss(new_name, &new_spec)) != fnfErr)
  33.         return(__io_error);
  34.     
  35.     if (old_spec.vRefNum != new_spec.vRefNum || old_spec.parID != new_spec.parID)
  36.         return(__io_error);
  37.     
  38.     pb.ioParam.ioNamePtr    = old_spec.name;
  39.     pb.ioParam.ioVRefNum    = old_spec.vRefNum;
  40.     pb.fileParam.ioFVersNum = 0;
  41.     pb.ioParam.ioMisc       = (Ptr) new_spec.name;
  42.     pb.fileParam.ioDirID    = old_spec.parID;
  43.     
  44.     return(io_result(PBHRenameSync(&pb)));      
  45. }
  46.